package trace

type SwComponment struct {
	Id     int32
	Name   string
	Server string
}

func GetComponent(componmentId int32) string {
	if len(componentIdMap) == 0 {
		componentIdMap = make(map[int32]*SwComponment)
		for _, componment := range components {
			componentIdMap[componment.Id] = componment
		}
	}
	if componment := componentIdMap[componmentId]; componment != nil {
		if componment.Server == "" {
			return componment.Name
		}
		return componment.Server
	}
	return "Unknown"
}

func GetServerName(componmentName string) string {
	if len(nameToServerMap) == 0 {
		nameToServerMap = make(map[string]string)
		for _, componment := range components {
			if componment.Server != "" {
				nameToServerMap[componment.Name] = componment.Server
			}
		}
	}
	if server, ok := nameToServerMap[componmentName]; ok {
		return server
	}
	return componmentName
}

var (
	components = []*SwComponment{
		{Id: 0, Name: "Unknown"},
		{Id: 1, Name: "Tomcat"},
		{Id: 2, Name: "HttpClient"},
		{Id: 3, Name: "Dubbo"},
		{Id: 4, Name: "H2"},
		{Id: 5, Name: "Mysql"},
		{Id: 6, Name: "ORACLE"},
		{Id: 7, Name: "Redis"},
		{Id: 8, Name: "Motan"},
		{Id: 9, Name: "MongoDB"},
		{Id: 10, Name: "Resin"},
		{Id: 11, Name: "Feign"},
		{Id: 12, Name: "OKHttp"},
		{Id: 13, Name: "SpringRestTemplate"},
		{Id: 14, Name: "SpringMVC"},
		{Id: 15, Name: "Struts2"},
		{Id: 16, Name: "NutzMVC"},
		{Id: 17, Name: "NutzHttp"},
		{Id: 18, Name: "JettyClient"},
		{Id: 19, Name: "JettyServer"},
		{Id: 20, Name: "Memcached"},
		{Id: 21, Name: "ShardingJDBC"},
		{Id: 22, Name: "PostgreSQL"},
		{Id: 23, Name: "GRPC"},
		{Id: 24, Name: "ElasticJob"},
		{Id: 25, Name: "RocketMQ"},
		{Id: 26, Name: "httpasyncclient"},
		{Id: 27, Name: "Kafka"},
		{Id: 28, Name: "ServiceComb"},
		{Id: 29, Name: "Hystrix"},
		{Id: 30, Name: "Jedis", Server: "Redis"},
		{Id: 31, Name: "SQLite"},
		{Id: 32, Name: "h2-jdbc-driver", Server: "H2"},
		{Id: 33, Name: "mysql-connector-java", Server: "Mysql"},
		{Id: 34, Name: "ojdbc"},
		{Id: 35, Name: "Spymemcached", Server: "Memcached"},
		{Id: 36, Name: "Xmemcached", Server: "Memcached"},
		{Id: 37, Name: "postgresql-jdbc-driver", Server: "PostgreSQL"},
		{Id: 38, Name: "rocketMQ-producer", Server: "RocketMQ"},
		{Id: 39, Name: "rocketMQ-consumer", Server: "RocketMQ"},
		{Id: 40, Name: "kafka-producer", Server: "Kafka"},
		{Id: 41, Name: "kafka-consumer", Server: "Kafka"},
		{Id: 42, Name: "mongodb-driver", Server: "MongoDB"},
		{Id: 43, Name: "SOFARPC"},
		{Id: 44, Name: "ActiveMQ"},
		{Id: 45, Name: "activemq-producer", Server: "ActiveMQ"},
		{Id: 46, Name: "activemq-consumer", Server: "ActiveMQ"},
		{Id: 47, Name: "Elasticsearch"},
		{Id: 48, Name: "transport-client", Server: "Elasticsearch"},
		{Id: 49, Name: "http"},
		{Id: 50, Name: "rpc"},
		{Id: 51, Name: "RabbitMQ"},
		{Id: 52, Name: "rabbitmq-producer", Server: "RabbitMQ"},
		{Id: 53, Name: "rabbitmq-consumer", Server: "RabbitMQ"},
		{Id: 54, Name: "Canal"},
		{Id: 55, Name: "Gson"},
		{Id: 56, Name: "Redisson", Server: "Redis"},
		{Id: 57, Name: "Lettuce", Server: "Redis"},
		{Id: 58, Name: "Zookeeper", Server: "Zookeeper"},
		{Id: 59, Name: "Vertx"},
		{Id: 60, Name: "ShardingSphere"},
		{Id: 61, Name: "spring-cloud-gateway"},
		{Id: 62, Name: "RESTEasy"},
		{Id: 63, Name: "SolrJ", Server: "Solr"},
		{Id: 64, Name: "Solr"},
		{Id: 65, Name: "SpringAsync"},
		{Id: 66, Name: "JdkHttp"},
		{Id: 67, Name: "spring-webflux"},
		{Id: 68, Name: "Play"},
		{Id: 69, Name: "cassandra-java-driver", Server: "Cassandra"},
		{Id: 70, Name: "Cassandra"},
		{Id: 71, Name: "Light4J"},
		{Id: 72, Name: "Pulsar"},
		{Id: 73, Name: "pulsar-producer", Server: "Pulsar"},
		{Id: 74, Name: "pulsar-consumer", Server: "Pulsar"},
		{Id: 75, Name: "Ehcache"},
		{Id: 76, Name: "SocketIO"},
		{Id: 77, Name: "rest-high-level-client", Server: "Elasticsearch"},
		{Id: 78, Name: "spring-tx"},
		{Id: 79, Name: "Armeria"},
		{Id: 80, Name: "JdkThreading"},
		{Id: 81, Name: "KotlinCoroutine"},
		{Id: 82, Name: "AvroServer"},
		{Id: 83, Name: "AvroClient"},
		{Id: 84, Name: "Undertow"},
		{Id: 85, Name: "Finagle"},
		{Id: 86, Name: "Mariadb"},
		{Id: 87, Name: "mariadb-jdbc", Server: "Mariadb"},
		{Id: 88, Name: "quasar"},
		{Id: 89, Name: "InfluxDB"},
		{Id: 90, Name: "influxdb-java", Server: "InfluxDB"},
		{Id: 91, Name: "brpc-java"},
		{Id: 92, Name: "GraphQL"},
		{Id: 93, Name: "spring-annotation"},
		{Id: 94, Name: "HBase"},
		{Id: 95, Name: "spring-kafka-consumer", Server: "kafka-consumer"},
		{Id: 96, Name: "SpringScheduled"},
		{Id: 97, Name: "quartz-scheduler"},
		{Id: 98, Name: "xxl-job"},
		{Id: 99, Name: "spring-webflux-webclient"},
		{Id: 100, Name: "thrift-server"},
		{Id: 101, Name: "thrift-client"},
		{Id: 102, Name: "AsyncHttpClient"},
		{Id: 103, Name: "dbcp"},
		{Id: 104, Name: "mssql-jdbc-driver", Server: "SqlServer"},
		{Id: 105, Name: "Apache-CXF"},
		{Id: 106, Name: "dolphinscheduler"},
		{Id: 107, Name: "JsonRpc"},
		{Id: 108, Name: "seata"},
		{Id: 109, Name: "MyBatis"},
		{Id: 110, Name: "tcp"},
		{Id: 111, Name: "AzureHttpTrigger"},
		{Id: 112, Name: "Neo4j"},
		{Id: 113, Name: "Sentinel"},
		{Id: 114, Name: "GuavaCache"},
		{Id: 115, Name: "AlibabaDruId"},
		{Id: 116, Name: "HikariCP"},
		{Id: 117, Name: "Fastjson"},
		{Id: 118, Name: "Jackson"},
		{Id: 119, Name: "ClickHouse-jdbc-driver", Server: "ClickHouse"},
		{Id: 120, Name: "ClickHouse"},
		{Id: 121, Name: "Apache-Kylin-jdbc-driver", Server: "Apache-Kylin"},
		{Id: 122, Name: "Apache-Kylin"},
		{Id: 123, Name: "GuavaEventBus"},
		{Id: 124, Name: "AWSLambdaTrigger"},
		{Id: 125, Name: "AWSLambdaGatewayAPIHTTP"},
		{Id: 126, Name: "AWSLambdaGatewayAPIREST"},
		{Id: 127, Name: "Apache-ShenYu"},
		{Id: 128, Name: "Hutool"},
		{Id: 129, Name: "https"},
		{Id: 130, Name: "tls"},
		{Id: 131, Name: "Micronaut"},
		{Id: 132, Name: "NATS"},
		{Id: 133, Name: "Impala-jdbc-driver", Server: "Impala"},
		{Id: 134, Name: "Impala"},
		{Id: 135, Name: "EventMesh"},
		{Id: 136, Name: "eventmesh-producer", Server: "EventMesh"},
		{Id: 137, Name: "eventmesh-consumer", Server: "EventMesh"},
		{Id: 138, Name: "AWSDynamoDB"},
		{Id: 139, Name: "AWSSNS"},
		{Id: 140, Name: "AWSSQS"},
		{Id: 141, Name: "Micrometer"},
		{Id: 142, Name: "mtls"},
		{Id: 143, Name: "amqp"},
		{Id: 144, Name: "amqp-producer", Server: "amqp"},
		{Id: 145, Name: "amqp-consumer", Server: "amqp"},
		{Id: 146, Name: "Jersey"},
		{Id: 147, Name: "Grizzly"},
		{Id: 148, Name: "WebSphere"},
		{Id: 149, Name: "Aerospike"},
		{Id: 150, Name: "Nacos"},
		{Id: 151, Name: "Netty-http"},
		{Id: 152, Name: "c3p0"},
		{Id: 153, Name: "Derby-jdbc-driver"},
		{Id: 154, Name: "Sqlite-jdbc-driver"},
		{Id: 155, Name: "Db2-jdbc-driver"},
		{Id: 156, Name: "Sybase-jdbc-driver"},
		{Id: 157, Name: "OceanBase-jdbc-driver"},
		{Id: 158, Name: "SolonMVC"},
		{Id: 159, Name: "DNS"},
		{Id: 3001, Name: "AspNetCore"},
		{Id: 3002, Name: "EntityFrameworkCore"},
		{Id: 3003, Name: "SqlClient", Server: "SqlServer"},
		{Id: 3004, Name: "CAP"},
		{Id: 3005, Name: "StackExchange.Redis", Server: "Redis"},
		{Id: 3006, Name: "SqlServer"},
		{Id: 3007, Name: "Npgsql", Server: "PostgreSQL"},
		{Id: 3008, Name: "MySqlConnector", Server: "Mysql"},
		{Id: 3009, Name: "EntityFrameworkCore.InMemory", Server: "InMemoryDatabase"},
		{Id: 3010, Name: "EntityFrameworkCore.SqlServer", Server: "SqlServer"},
		{Id: 3011, Name: "EntityFrameworkCore.Sqlite", Server: "SQLite"},
		{Id: 3012, Name: "Pomelo.EntityFrameworkCore.MySql", Server: "Mysql"},
		{Id: 3013, Name: "Npgsql.EntityFrameworkCore.PostgreSQL", Server: "PostgreSQL"},
		{Id: 3014, Name: "InMemoryDatabase"},
		{Id: 3015, Name: "AspNet"},
		{Id: 3016, Name: "SmartSql"},
		{Id: 3017, Name: "FreeSql"},
		{Id: 3018, Name: "FreeRedis", Server: "Redis"},
		{Id: 4001, Name: "HttpServer"},
		{Id: 4002, Name: "Express"},
		{Id: 4003, Name: "Egg"},
		{Id: 4004, Name: "Koa"},
		{Id: 4005, Name: "Axios"},
		{Id: 4006, Name: "Mongoose"},
		{Id: 5001, Name: "ServiceCombMesher"},
		{Id: 5002, Name: "ServiceCombServiceCenter"},
		{Id: 5003, Name: "MOSN"},
		{Id: 5004, Name: "GoHttpServer"},
		{Id: 5005, Name: "GoHttpClient"},
		{Id: 5006, Name: "Gin"},
		{Id: 5007, Name: "Gear"},
		{Id: 5008, Name: "GoMicroClient"},
		{Id: 5009, Name: "GoMicroServer"},
		{Id: 5010, Name: "Kratos"},
		{Id: 5012, Name: "GoMysql", Server: "Mysql"},
		{Id: 5013, Name: "OpenFunction"},
		{Id: 5014, Name: "GoRedis", Server: "Redis"},
		{Id: 5015, Name: "Echo"},
		{Id: 5016, Name: "Lock"},
		{Id: 5017, Name: "GoMuxServer"},
		{Id: 5018, Name: "Iris"},
		{Id: 5019, Name: "GoFastHttpClient"},
		{Id: 5020, Name: "GoFastHttpServer"},
		{Id: 5021, Name: "Fiber"},
		{Id: 5022, Name: "GoFrame"},
		{Id: 5023, Name: "GoZero"},
		{Id: 6000, Name: "Nginx"},
		{Id: 6001, Name: "Kong"},
		{Id: 6002, Name: "APISIX"},
		{Id: 7000, Name: "Python"},
		{Id: 7001, Name: "Flask"},
		{Id: 7002, Name: "Requests"},
		{Id: 7003, Name: "PyMysql", Server: "Mysql"},
		{Id: 7004, Name: "Django"},
		{Id: 7005, Name: "Tornado"},
		{Id: 7006, Name: "Urllib3"},
		{Id: 7007, Name: "Sanic"},
		{Id: 7008, Name: "AioHttp"},
		{Id: 7009, Name: "PyramId"},
		{Id: 7010, Name: "Psychopg", Server: "PostgreSQL"},
		{Id: 7011, Name: "Celery"},
		{Id: 7012, Name: "Falcon"},
		{Id: 7013, Name: "MysqlClient", Server: "Mysql"},
		{Id: 7014, Name: "FastAPI"},
		{Id: 7015, Name: "Bottle"},
		{Id: 7016, Name: "AsyncPG", Server: "PostgreSQL"},
		{Id: 7017, Name: "AIORedis", Server: "Redis"},
		{Id: 7018, Name: "Websockets"},
		{Id: 7019, Name: "HTTPX"},
		{Id: 8001, Name: "PHP"},
		{Id: 8002, Name: "cURL"},
		{Id: 8003, Name: "PDO"},
		{Id: 8004, Name: "Mysqli", Server: "Mysql"},
		{Id: 8005, Name: "Yar"},
		{Id: 8006, Name: "Predis", Server: "Redis"},
		{Id: 9000, Name: "EnvoyProxy"},
		{Id: 10000, Name: "JavaScript"},
		{Id: 10001, Name: "ajax"},
		{Id: 11000, Name: "Rust"},
	}
	componentIdMap  map[int32]*SwComponment
	nameToServerMap map[string]string
)
